<template>
  <el-dialog title="测区外问题录入" :visible.sync="show" :close-on-click-modal="false" width="1000px" @closed="closed">
    <div class="course-info" style="margin-top: -20px">
      <div class="item">
        <span>所属部门：</span><span>{{ courseRow.showDeptName }}</span>
      </div>
      <div class="item">
        <span>项目：</span><span>{{ courseRow.projectName }}</span>
      </div>
      <div class="item">
        <span>施工单位：</span><span>{{ courseRow.constructionName }}</span>
      </div>
      <div class="item" v-if="processType == 'handcover'">
        <span>标段：</span><span>{{ courseRow.section }}</span>
      </div>
      <div class="item">
        <span>检查人员：</span><span>{{ courseRow.principalUserName || '/' }}</span>
      </div>
      <div class="item">
        <span>检查时间：</span><span>{{ courseRow.checkDate }}</span>
      </div>
    </div>

    <el-table v-loading="listLoading" :data="list" size="small" height="calc(88vh - 250px)" style="min-height: 300px">
      <el-table-column label="序号" type="index" width="50" />
      <el-table-column label="问题描述" prop="outsideDesc" show-overflow-tooltip min-width="120" />
      <el-table-column label="问题部位" prop="outsidePostion" show-overflow-tooltip min-width="120" />
      <el-table-column label="操作" align="center" width="120" fixed="right">
        <template slot-scope="{ row }">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="$refs.EditItem.open(row)">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" :loading="row.removeLoading" @click="handleDelete(row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="footer-box" slot="footer">
      <div>
        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
      </div>
      <div>
        <el-button size="small" icon="el-icon-plus" type="primary" :disabled="listLoading" @click="$refs.EditItem.open({ taskId: queryParams.taskId })">新 增</el-button>
        <el-button size="small" @click="show = false">关 闭</el-button>
      </div>
    </div>
    <EditItem ref="EditItem" v-model="showEditItem" @ok="getList" />
  </el-dialog>
</template>
<script>
// 测区外问题录入列表对话框
import { listOutsideQues, delOutsideQues } from '@/api/qualityManage/cq'
import EditItem from './EditOutsideQues'
export default {
  name: 'OutsideQuesList',
  components: { EditItem },
  data() {
    return {
      show: false,
      listLoading: false,
      total: 0,
      list: [],
      queryParams: { pageNum: 1, pageSize: 2, taskId: '' },
      processType: '',
      courseRow: {},
      showEditItem: false
    }
  },
  methods: {
    closed() {
      this.listLoading = false
      this.total = 0
      this.list = []
      this.queryParams = { pageNum: 1, pageSize: 10, taskId: '' }
      this.courseRow = {}
    },
    open(item = {}) {
      if (!item.randomId) return this.$message.warning('randomId 不能为空')
      this.queryParams.taskId = item.randomId
      this.processType = item.processType
      this.courseRow = item
      this.show = true
      this.getList()
    },
    async getList() {
      this.listLoading = true
      const res = await listOutsideQues(this.queryParams).catch(() => false)
      this.listLoading = false
      if (res === false) return

      const data = res.rows || []
      data.map(i => {
        i.removeLoading = false
      })
      this.list = data
      this.total = res.total || 0
    },
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    async handleDelete(item) {
      if (item.removeLoading) return
      const res1 = await this.$confirm(`确认删除数据项：${item.outsideDesc}?`, '警告', { type: 'warning' }).catch(() => false)
      if (res1 !== 'confirm') return

      item.removeLoading = true
      const res = await delOutsideQues(item.outsideQuesId).catch(() => false)
      item.removeLoading = false
      if (res === false) return

      this.msgSuccess('删除成功')
      this.list.length > 1 ? this.getList() : this.handleQuery()
    }
  }
}
</script>
<style lang="scss" scoped>
.course-info {
  display: flex;
  flex-wrap: wrap;
  border-bottom: 1px solid #e4e7ed;
  padding-bottom: 10px;
  .item {
    margin: 0 40px 10px 0;
    span:nth-child(1) {
      display: inline-block;
      margin-right: 10px;
    }
    span:nth-child(2) {
      display: inline-block;
      min-width: 80px;
      font-weight: bold;
      background-color: #eff2f9;
      padding: 0 10px;
      height: 30px;
      line-height: 30px;
      border-radius: 4px;
      vertical-align: middle;
    }
  }
}
.footer-box {
  display: flex;
  justify-content: space-between;
  /deep/ .pagination-container {
    margin: unset;
    padding: unset !important;
    .el-pagination {
      position: relative;
    }
  }
}
</style>
